import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// vue-router 重复点击菜单栏报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: () => import('@/views/User/Login.vue')
    },
    {
      path: '/PrivacyPolicy',
      name: 'PrivacyPolicy',
      component: () => import('@/views/User/PrivacyPolicy.vue')
    },
    {
      path: '/ForgetPassword',
      name: 'ForgetPassword',
      component: () => import('@/views/User/ForgetPassword.vue')
    },
    {
      path: '/Register',
      name: 'Register',
      component: () => import('@/views/User/Register.vue')
    },
    {
      path: '/Home',
      name: 'Home',
      component: () => import('@/components/Home.vue'),
      redirect: '/Dashbord',
      children: [
        {
          path: '/Dashbord',
          name: 'Dashbord',
          component: () => import('@/views/Dashbord/index.vue')
        },
        {
          path: '/Apply',
          name: 'Apply',
          component: () => import('@/views/Dashbord/Apply/index.vue')
        },
        {
          path: '/ApplyMessage',
          name: 'ApplyMessage',
          component: () => import('@/views/Dashbord/ApplyMessage/index.vue')
        },
        {
          path: '/Camera',
          name: 'Camera',
          component: () => import('@/views/Dashbord/ApplyMessage/Camera.vue')
        },
        {
          path: '/My',
          name: 'My',
          component: () => import('@/views/My/index.vue')
        },
        {
          path: '/Message',
          name: 'Message',
          component: () => import('@/views/Message/index.vue')
        },
        {
          path: '/MessageDetails',
          name: 'MessageDetails',
          component: () => import('@/views/Message/MessageDetails/index.vue')
        },
        {
          path: '/Work',
          name: 'Work',
          component: () => import('@/views/Work/index.vue')
        },
        {
          path: '/HotCardManage',
          name: 'HotCardManage',
          component: () => import('@/views/Work/HotCardManage/index.vue')
        },
        {
          path: '/AddHotCard',
          name: 'AddHotCard',
          component: () => import('@/views/Work/HotCardManage/AddHotCard/index.vue')
        },
        {
          path: '/HotCardDetails',
          name: 'HotCardDetails',
          component: () => import('@/views/Work/HotCardManage/HotCardDetails/index.vue')
        },
        {
          path: '/OvertimePayManage',
          name: 'OvertimePayManage',
          component: () => import('@/views/Work/OvertimePayManage/index.vue')
        },
        {
          path: '/AddOvertimePay',
          name: 'AddOvertimePay',
          component: () => import('@/views/Work/OvertimePayManage/AddOvertimePay/index.vue')
        },
        {
          path: '/SignManage',
          name: 'SignManage',
          component: () => import('@/views/Work/SignManage/index.vue')
        },
        {
          path: '/AddSignManage',
          name: 'AddSignManage',
          component: () => import('@/views/Work/SignManage/AddSignManage/index.vue')
        },
        {
          path: '/SignScan',
          name: 'SignScan',
          component: () => import('@/views/Work/SignManage/SignScan/index.vue')
        },
        {
          path: '/HistoryRecord',
          name: 'HistoryRecord',
          component: () => import('@/views/Work/SignManage/HistoryRecord/index.vue')
        },
        {
          path: '/HistoryDetails',
          name: 'HistoryDetails',
          component: () => import('@/views/Work/SignManage/HistoryDetails/index.vue')
        },
        {
          path: '/MaterialManage',
          name: 'MaterialManage',
          component: () => import('@/views/Work/MaterialManage/index.vue')
        },
        {
          path: '/MaterialDetails',
          name: 'MaterialDetails',
          component: () => import('@/views/Work/MaterialManage/MaterialDetails/index.vue')
        },
        {
          path: '/MaterialOutbound',
          name: 'MaterialOutbound',
          component: () => import('@/views/Work/MaterialManage/MaterialOutbound/index.vue')
        },
        {
          path: '/MaterialOutboundHistory',
          name: 'MaterialOutboundHistory',
          component: () => import('@/views/Work/MaterialManage/MaterialOutboundHistory/index.vue')
        },
        {
          path: '/OvertimePayDetails',
          name: 'OvertimePayDetails',
          component: () => import('@/views/Work/OvertimePayManage/OvertimePayDetails/index.vue')
        },
        {
          path: '/ChoosePersonalOvertime',
          name: 'ChoosePersonalOvertime',
          component: () => import('@/views/Work/OvertimePayManage/ChoosePersonal/index.vue')
        },
        {
          path: '/CostLiveManage',
          name: 'CostLiveManage',
          component: () => import('@/views/Work/CostLiveManage/index.vue')
        },
        {
          path: '/CostLiveDetails',
          name: 'CostLiveDetails',
          component: () => import('@/views/Work/CostLiveManage/CostLiveDetails/index.vue')
        },
        {
          path: '/Team',
          name: 'Team',
          component: () => import('@/views/Work/Team/index.vue')
        },
        {
          path: '/NotSignIn',
          name: 'NotSignIn',
          component: () => import('@/views/Work/Team/NotSignIn/index.vue')
        },
        {
          path: '/AreaAttendance',
          name: 'AreaAttendance',
          component: () => import('@/views/Work/Team/AreaAttendance/index.vue')
        },
        {
          path: '/DangerProject',
          name: 'DangerProject',
          component: () => import('@/views/Work/DangerProject/index.vue')
        },
        {
          path: '/DangerProjectDetails',
          name: 'DangerProjectDetails',
          component: () => import('@/views/Work/DangerProject/DangerProjectDetails/index.vue')
        },
        {
          path: '/PersonalManage',
          name: 'PersonalManage',
          component: () => import('@/views/Work/PersonalManage/index.vue')
        },
        {
          path: '/PersonalStatistical',
          name: 'PersonalStatistical',
          component: () => import('@/views/Work/PersonalManage/PersonalStatistical/index.vue')
        },
        {
          path: '/AddReported',
          name: 'AddReported',
          component: () => import('@/views/Work/PersonalManage/AddReported/index.vue')
        },
        {
          path: '/ScheduleManage',
          name: 'ScheduleManage',
          component: () => import('@/views/Work/ScheduleManage/index.vue')
        },
        {
          path: '/ScheduleReport',
          name: 'ScheduleReport',
          component: () => import('@/views/Work/ScheduleManage/ScheduleReport/index.vue')
        },
        {
          path: '/AddressBook',
          name: 'AddressBook',
          component: () => import('@/views/Work/AddressBook/index.vue')
        },
        {
          path: '/Attendance',
          name: 'Attendance',
          component: () => import('@/views/Work/Attendance/index.vue')
        },
        {
          path: '/SearchAttendance',
          name: 'SearchAttendance',
          component: () => import('@/views/Work/AttendanceStatistics/SearchAttendance/index.vue')
        },
        {
          path: '/WorkTypeAttendance',
          name: 'WorkTypeAttendance',
          component: () => import('@/views/Work/AttendanceStatistics/WorkTypeAttendance/index.vue')
        },
        {
          path: '/AttendanceStatistics',
          name: 'AttendanceStatistics',
          component: () => import('@/views/Work/AttendanceStatistics/index.vue')
        },
        {
          path: '/CarOut',
          name: 'CarOut',
          component: () => import('@/views/Work/CarOut/index.vue')
        },
        {
          path: '/PlateOcr',
          name: 'PlateOcr',
          component: () => import('@/views/Work/CarOut/PlateOcr/index.vue')
        },
        {
          path: '/EnvironmentalMonitor',
          name: 'EnvironmentalMonitor',
          component: () => import('@/views/Work/EnvironmentalMonitor/index.vue')
        },
        {
          path: '/RectificationTask',
          name: 'RectificationTask',
          component: () => import('@/views/Work/FixedInspection/RectificationTask/index.vue')
        },
        {
          path: '/FixedTaskDetails',
          name: 'FixedTaskDetails',
          component: () => import('@/views/Work/FixedInspection/FixedTaskDetails/index.vue')
        },
        {
          path: '/VisitorsManage',
          name: 'VisitorsManage',
          component: () => import('@/views/Work/VisitorsManage/index.vue')
        },
        {
          path: '/VisitorDetails',
          name: 'VisitorDetails',
          component: () => import('@/views/Work/VisitorsManage/VisitorDetails/index.vue')
        },
        {
          path: '/IllegalQuery',
          name: 'IllegalQuery',
          component: () => import('@/views/Work/IllegalQuery/index.vue')
        },
        {
          path: '/IllegalStatistical',
          name: 'IllegalStatistical',
          component: () => import('@/views/Work/IllegalQuery/IllegalStatistical/index.vue')
        },
        {
          path: '/FixedInspection',
          name: 'FixedInspection',
          component: () => import('@/views/Work/FixedInspection/index.vue')
        },
        {
          path: '/FixedStatistical',
          name: 'FixedStatistical',
          component: () => import('@/views/Work/FixedInspection/FixedStatistical/index.vue')
        },
        {
          path: '/MyInspection',
          name: 'MyInspection',
          component: () => import('@/views/Work/FixedInspection/myInspection/index.vue')
        },
        {
          path: '/InspectionRecord',
          name: 'InspectionRecord',
          component: () => import('@/views/Work/FixedInspection/InspectionRecord/index.vue')
        },
        {
          path: '/InspectionRegistration',
          name: 'InspectionRegistration',
          component: () => import('@/views/Work/FixedInspection/InspectionRegistration/index.vue')
        },
        {
          path: '/InspectionRegistrationScan',
          name: 'InspectionRegistrationScan',
          component: () => import('@/views/Work/FixedInspection/InspectionRegistrationScan/index.vue')
        },
        {
          path: '/RealTimeInspection',
          name: 'RealTimeInspection',
          component: () => import('@/views/Work/RealTimeInspection/index.vue')
        },
        {
          path: '/TypeStatistical',
          name: 'TypeStatistical',
          component: () => import('@/views/Work/RealTimeInspection/TypeStatistical/index.vue')
        },
        {
          path: '/RealTimeStatistical',
          name: 'RealTimeStatistical',
          component: () => import('@/views/Work/RealTimeInspection/RealTimeStatistical/index.vue')
        },
        {
          path: '/RealTimeRectificationTask',
          name: 'RealTimeRectificationTask',
          component: () => import('@/views/Work/RealTimeInspection/RealTimeRectificationTask/index.vue')
        },
        {
          path: '/RealTaskDetails',
          name: 'RealTaskDetails',
          component: () => import('@/views/Work/RealTimeInspection/RealTaskDetails/index.vue')
        },
        {
          path: '/RealTimeTaskDetails',
          name: 'RealTimeTaskDetails',
          component: () => import('@/views/Work/RealTimeInspection/RealTimeTaskDetails/index.vue')
        },
        {
          path: '/InitiateRealTime',
          name: 'InitiateRealTime',
          component: () => import('@/views/Work/RealTimeInspection/InitiateRealTime/index.vue')
        },
        {
          path: '/ChoosePersonal',
          name: 'ChoosePersonal',
          component: () => import('@/views/Work/RealTimeInspection/ChoosePersonal/index.vue')
        },
        {
          path: '/PersonalList',
          name: 'PersonalList',
          component: () => import('@/views/Work/RealTimeInspection/PersonalList/index.vue')
        },
        {
          path: '/SignIn',
          name: 'SignIn',
          component: () => import('@/views/Work/SignIn/index.vue')
        },
        {
          path: '/SignCamera',
          name: 'SignCamera',
          component: () => import('@/views/Work/SignIn/SignCamera/index.vue')
        },
        {
          path: '/MassManage',
          name: 'MassManage',
          component: () => import('@/views/Work/MassManage/index.vue')
        },
        {
          path: '/AddMass',
          name: 'AddMass',
          component: () => import('@/views/Work/MassManage/AddMass/index.vue')
        },
        {
          path: '/MassDetails',
          name: 'MassDetails',
          component: () => import('@/views/Work/MassManage/MassDetails/index.vue')
        },
        {
          path: '/MassReport',
          name: 'MassReport',
          component: () => import('@/views/Work/MassManage/MassReport/index.vue')
        },
        {
          path: '/HardwareManage',
          name: 'HardwareManage',
          component: () => import('@/views/Work/HardwareManage/index.vue')
        },
        {
          path: '/HardwareDetails',
          name: 'HardwareDetails',
          component: () => import('@/views/Work/HardwareManage/HardwareDetails/index.vue')
        },
        {
          path: '/HardwareListDetails',
          name: 'HardwareListDetails',
          component: () => import('@/views/Work/HardwareManage/HardwareListDetails/index.vue')
        },
        {
          path: '/LifterDetails',
          name: 'LifterDetails',
          component: () => import('@/views/Work/HardwareManage/LifterDetails/index.vue')
        },
        {
          path: '/DormManage',
          name: 'DormManage',
          component: () => import('@/views/Work/DormManage/index.vue')
        },
        {
          path: '/DormReport',
          name: 'DormReport',
          component: () => import('@/views/Work/DormManage/DormReport/index.vue')
        },
        {
          path: '/ViolationAdd',
          name: 'ViolationAdd',
          component: () => import('@/views/Work/ViolationAdd/index.vue')
        },
        {
          path: '/Video',
          name: 'Video',
          component: () => import('@/views/Work/Video/index.vue')
        },
        {
          path: '/VideoDetails',
          name: 'VideoDetails',
          component: () => import('@/views/Work/Video/VideoDetails/index.vue')
        },
        {
          path: '/Setting',
          name: 'Setting',
          component: () => import('@/views/my/Setting/index.vue')
        },
        {
          path: '/About',
          name: 'About',
          component: () => import('@/views/My/About/index.vue')
        },
        {
          path: '/MyProject',
          name: 'MyProject',
          component: () => import('@/views/My/MyProject/index.vue')
        },
        {
          path: '/Personal',
          name: 'Personal',
          component: () => import('@/views/My/Personal/index.vue')
        },
        {
          path: '/SettingHome',
          name: 'SettingHome',
          component: () => import('@/views/My/setting/SettingHome/index.vue')
        },
        {
          path: '/UpdatePassword',
          name: 'UpdatePassword',
          component: () => import('@/views/My/Setting/UpdatePassword/index.vue')
        },
        {
          path: '/ProjectDetails',
          name: 'ProjectDetails',
          component: () => import('@/views/My/MyProject/ProjectDetails/index.vue')
        },
        {
          path: '/ProjectCode',
          name: 'ProjectCode',
          component: () => import('@/views/My/MyProject/ProjectCode/index.vue')
        },
        {
          path: '/MyCode',
          name: 'MyCode',
          component: () => import('@/views/My/MyCode/index.vue')
        },
      ]
    },
  ],
})

router.beforeEach((to, from, next) => {
    if (to.path === '/' || to.path === '/Register' || to.path === '/ForgetPassword' || to.path === '/PrivacyPolicy' ) {
      next();
    } else {
      let token = localStorage.getItem('token');
      if (token === null || token === '') {
        next('/');
      } else {
        next();
      }
    }
  })

export default router
